home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr54 / bison118.zip / MAIN.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  4KB  |  139 lines

  1. /* Top level entry point of bison,
  2.    Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of Bison, the GNU Compiler Compiler.
  5.  
  6. Bison is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Bison is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Bison; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include "system.h"
  23. #include "machine.h"    /* JF for MAXSHORT */
  24.  
  25. extern    int lineno;
  26. extern    int verboseflag;
  27.  
  28. /* Nonzero means failure has been detected; don't write a parser file.  */
  29. int failure;
  30.  
  31. /* The name this program was run with, for messages. */
  32. char *program_name;
  33.  
  34. extern void getargs(), openfiles(), reader(), reduce_grammar();
  35. extern void set_derives(), set_nullable(), generate_states();
  36. extern void lalr(), initialize_conflicts(), verbose(), terse();
  37. extern void output(), done(), abort();
  38.  
  39.  
  40. /* VMS complained about using `int'.  */
  41. int
  42. main(argc, argv)
  43. int argc;
  44. char *argv[];
  45. {
  46.   program_name = argv[0];
  47.   failure = 0;
  48.   lineno = 0;
  49.   getargs(argc, argv);
  50.   openfiles();
  51.  
  52.   /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
  53.      In file reader.c.
  54.      The other parts are recorded in the grammar; see gram.h.  */
  55.   reader();
  56.  
  57.   /* find useless nonterminals and productions and reduce the grammar.  In
  58.      file reduce.c */
  59.   reduce_grammar();
  60.  
  61.   /* record other info about the grammar.  In files derives and nullable.  */
  62.   set_derives();
  63.   set_nullable();
  64.  
  65.   /* convert to nondeterministic finite state machine.  In file LR0.
  66.      See state.h for more info.  */
  67.   generate_states();
  68.  
  69.   /* make it deterministic.  In file lalr.  */
  70.   lalr();
  71.  
  72.   /* Find and record any conflicts: places where one token of lookahead is not
  73.      enough to disambiguate the parsing.  In file conflicts.
  74.      Currently this does not do anything to resolve them;
  75.      the trivial form of conflict resolution that exists is done in output.  */
  76.   initialize_conflicts();
  77.  
  78.   /* print information about results, if requested.  In file print. */
  79.   if (verboseflag)
  80.     verbose();
  81.   else
  82.     terse();
  83.  
  84.   /* output the tables and the parser to ftable.  In file output. */
  85.   output();
  86.   done(failure);
  87. }
  88.  
  89. /* functions to report errors which prevent a parser from being generated */
  90.  
  91. void
  92. fatal(s)
  93. char *s;
  94. {
  95.   extern char *infile;
  96.  
  97.   if (infile == 0)
  98.     fprintf(stderr, "fatal error: %s\n", s);
  99.   else
  100.     fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  101.   done(1);
  102. }
  103.  
  104.  
  105. /* JF changed to accept/deal with variable args.  Is a real kludge since
  106.    we don't support _doprnt calls */
  107. /*VARARGS1*/
  108.  
  109. void
  110. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  111. char *fmt;
  112. {
  113.   char buffer[200];
  114.  
  115.   sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  116.   fatal(buffer);
  117. }
  118.  
  119.  
  120. void
  121. toomany(s)
  122. char *s;
  123. {
  124.   char buffer[200];
  125.  
  126.     /* JF new msg */
  127.   sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  128.   fatal(buffer);
  129. }
  130.  
  131.  
  132. void
  133. berror(s)
  134. char *s;
  135. {
  136.   fprintf(stderr, "internal error, %s\n", s);
  137.   abort();
  138. }
  139.